home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / DJINC106.ARJ / INDSTREA.H < prev    next >
C/C++ Source or Header  |  1992-03-29  |  3KB  |  67 lines

  1. //    This is part of the iostream library, providing -*- C++ -*- input/output.
  2. //    Copyright (C) 1992 Per Bothner.
  3. //
  4. //    This library is free software; you can redistribute it and/or
  5. //    modify it under the terms of the GNU Library General Public
  6. //    License as published by the Free Software Foundation; either
  7. //    version 2 of the License, or (at your option) any later version.
  8. //
  9. //    This library is distributed in the hope that it will be useful,
  10. //    but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  12. //    Library General Public License for more details.
  13. //
  14. //    You should have received a copy of the GNU Library General Public
  15. //    License along with this library; if not, write to the Free
  16. //    Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17.  
  18. #ifndef _INDSTREAM_H
  19. #define _INDSTREAM_H
  20.  
  21. #ifdef __GNUG__
  22. #pragma interface
  23. #endif
  24.  
  25. #include <iostream.h>
  26.  
  27. // An indirectbuf is one that forwards all of its I/O requests
  28. // to another streambuf.
  29. // All get-related requests are sent to get_stream().
  30. // All put-related requests are sent to put_stream().
  31.  
  32. // An indirectbuf can be used to implement Common Lisp
  33. // synonym-streams and two-way-streams.
  34. //
  35. // class synonymbuf : public indirectbuf {
  36. //    Symbol *sym;
  37. //    synonymbuf(Symbol *s) { sym = s; }
  38. //    virtual streambuf *find_get_stream(int mode) {
  39. //        return coerce_to_streambuf(lookup_value(sym)); }
  40. // };
  41.  
  42. class indirectbuf : public streambuf {
  43.   protected:
  44.     streambuf *_get_stream;  // Optional cache for get_stream().
  45.     streambuf *_put_stream;  // Optional cache for put_stream().
  46.     int _delete_flags;
  47.   public:
  48.     streambuf *get_stream()
  49.     { return _get_stream ? _get_stream : lookup_stream(ios::in); }
  50.     streambuf *put_stream()
  51.     { return _put_stream ? _put_stream : lookup_stream(ios::out); }
  52.     virtual streambuf *lookup_stream(int mode) { return NULL; } // ERROR!
  53.     indirectbuf(streambuf *get=NULL, streambuf *put=NULL, int delete_mode=0);
  54.     virtual ~indirectbuf();
  55.     virtual int sputn(const char* s, int n);
  56.     virtual int sgetn(char* s, int n);
  57.     virtual int underflow();
  58.     virtual int overflow(int c = EOF);
  59.     virtual streampos seekoff(streamoff, _seek_dir, int mode=ios::in|ios::out);
  60.     virtual streampos seekpos(streampos pos, int mode = ios::in|ios::out);
  61.     virtual int sync();
  62.     virtual int pbackfail(int c);
  63.     virtual int ungetfail();
  64. };
  65.  
  66. #endif /* !_INDSTREAM_H */
  67.